//
//  feedbackViewController.m
//  ZIVSetView
//
//  Created by ziv on 16/9/8.
//  Copyright © 2016年 Ziv. All rights reserved.
//

#import "feedbackViewController.h"
#import "Masonry.h"

static NSString *cellID = @"cellID";
@interface feedbackViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation feedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
     self.navigationItem.title = @"意见与反馈";
    [self setupUI];
//    // 组头灰色
//    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    // Do any additional setup after loading the view.
}

//
//-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
//
//{
//    view.tintColor = [UIColor grayColor];
//    //YourColor： view.tintColor = WTGayColor(240);
//    
//}
-(void)setupUI
{
    
    UITableView *tv = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
   
    tv.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:tv];
    tv.delegate = self;
    tv.dataSource = self;
    [tv registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    tv.separatorStyle = UITableViewCellSeparatorStyleNone;
    tv.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 180)];
    tv.tableHeaderView.backgroundColor =[UIColor lightGrayColor];
    UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, tv.tableHeaderView.frame.size.width,tv.tableHeaderView.frame.size.height -130)];

    
                     
    [tv.tableHeaderView addSubview:tf];
    

    tf.placeholder = @"请输入您宝贵的反馈...";

    tf.font = [UIFont systemFontOfSize:14];
    
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(314, 155, 60, 25)];
    btn.backgroundColor = [UIColor blueColor];
//    btn.titleLabel.text = @"提交反馈";
    [btn setTitle:@"提交反馈" forState:UIControlStateNormal];
    btn.font =[UIFont systemFontOfSize:14];
    [btn addTarget:self action:@selector(tired) forControlEvents:UIControlEventTouchUpInside];
    //    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//    
//        make.top.equalTo(tv.mas_bottom).offset(0);
//        make.trailing.equalTo(tv.mas_trailing);
//        make.bottom.equalTo(tv.tableHeaderView.bottomAnchor);
//    }];
    [tv.tableHeaderView addSubview:btn];
    

}
-(void)tired{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"提交成功" preferredStyle:UIAlertControllerStyleAlert];
    //确定action
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  //  [self.view endEditing: YES];
    [self.view resignFirstResponder];
    //取消
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
 
    //添加action
    [alertController addAction:confirmAction];
    [alertController addAction:cancelAction];
    //显示
    [self presentViewController:alertController animated:YES completion:nil];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

  
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        cell.textLabel.text = @"客服电话:110-120";
        cell.textLabel.font = [UIFont systemFontOfSize:14];
    }
        
    if (indexPath.section == 0 && indexPath.row == 1)
    {
        cell.textLabel.text = @"用户交流群:741119120";
        cell.textLabel.font = [UIFont systemFontOfSize:14];

    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    if (indexPath.section == 0 && indexPath.row == 0) {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"拨打客服电话" message:@"110-120" preferredStyle:UIAlertControllerStyleAlert];
        //确定action
        UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        //取消
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        //添加action
        [alertController addAction:confirmAction];
        [alertController addAction:cancelAction];
        //显示
        [self presentViewController:alertController animated:YES completion:nil];
    }else if (indexPath.section == 0 && indexPath.row == 1)
    {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"加入用户交流群" message:@"741119120" preferredStyle:UIAlertControllerStyleAlert];
        //确定action
        UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        //取消
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        //添加action
        [alertController addAction:confirmAction];
        [alertController addAction:cancelAction];
        //显示
        [self presentViewController:alertController animated:YES completion:nil];
    
    
    
    }


}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 2;
    
 }


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{
    
        if (section == 0) {
        return @"欢迎联系我们";
    }


    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
